package com.example.springboot06db;

import com.example.springboot06db.dao.UserDao;
import com.example.springboot06db.entity.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import javax.sql.DataSource;

@SpringBootApplication
public class Springboot06DbApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Springboot06DbApplication.class, args);
        DataSource dataSource = context.getBean(DataSource.class);
        System.out.println("-----------------连接池数据源--------------");
        System.out.println(dataSource);

        System.out.println("-----------------项目启动-----------------");
        String port = context.getEnvironment().getProperty("server.port");
        System.out.println("http://localhost:" + port);

        UserDao dao = context.getBean(UserDao.class);
        User user = dao.getUser(1L);
        System.out.println("-----------------输出姓名-----------------");
        System.out.println(user);
    }

}
